import { createRouter, createWebHistory } from 'vue-router'
import {getCache} from "@/utils/cache";


const routes = [
    {
        path: '/',
        redirect: '/main'
    },
    {
        path: '/login',
        name: 'login',
        component: () => import('@/views/login/index.vue')
    },
    {
        path: '/main',
        name: 'main',
        component: () => import('@/views/main/index.vue')
    },
    {
        path: '/:pathMatch(.*)*',
        component: () => import('@/views/not-fount/index.vue')
    }
]


const router = createRouter({
    history: createWebHistory(),
    routes
})

router.beforeEach((to)=>{
    if (!getCache('token')){
        if (to.path !== '/login'){
            router.push('/login')
        }
    }
})



export default router